package com.kechen.search.controller;

import com.kechen.search.pojo.User;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 0xHertz
 * @Date: 2022/11/5 0005 10:23
 * @Description: 控制器
 **/
@RestController
public class MyController {
    @RequestMapping("/search")
    public String index() {
        return "搜索成功!";
    }


    // 测试fegin参数传递
    @GetMapping("/user/{id}")
    @HystrixCommand(fallbackMethod = "findByIdFallBack")
    public User findById(@PathVariable Integer id){
        // 人为制造异常
        int i = 1/0;
        return new User(1,"张三",23);
    }
    public User findByIdFallBack(){
        return new User(0,"出现问题来了",0);
    }

    @GetMapping("/getUser")
    public User getUser(@RequestParam Integer id,@RequestParam String name){
        return new User(id,name,23);
    }

    @PostMapping("/save")
    public User save(@RequestBody User customer){
        return customer;
    }
}
